﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlServerCe;

namespace ProjectoPV_ESW.Account.Fotografias
{
    /// <summary>
    /// Classe desenvolvida por Mário Pereira.
    /// </summary>
    public partial class AdicionarFotografia : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public DateTime Data { get; set; }
        public string Path { get; set; }
        public string Descricao { get; set; }
        public int Crianca { get; set; }
        public int Sala { get; set; }

        protected void ButtonAdicionar_Click(object sender, EventArgs e)
        {
            Data = Calendar1.SelectedDate;
            Path = TextBox1.Text;
            Descricao = TextBox2.Text;
            Crianca = System.Convert.ToInt32(DropDownList1.SelectedItem.Value);
            Sala = System.Convert.ToInt32(DropDownList2.SelectedItem.Value);

            if (Data == null && Path != "")
                LabelErr.Text = "Por favor preencha todos os dados!";
            else
            {
                string connectionStringJardim = ConfigurationManager.ConnectionStrings["JardimEntitiesString"].ConnectionString;
                SqlCeConnection conn = new SqlCeConnection(connectionStringJardim);
                string commandText = @"INSERT INTO Foto(Sala_SalaId,Crianca_CriancaId,Path,Descricao,DataFoto) VALUES (@sala, @crianca, @path, @desc, @dataFoto)";
                SqlCeCommand sqlinsertfotoCommand = new SqlCeCommand(commandText, conn);
                sqlinsertfotoCommand.Parameters.AddWithValue("@sala", Sala);
                sqlinsertfotoCommand.Parameters.AddWithValue("@crianca", Crianca);
                sqlinsertfotoCommand.Parameters.AddWithValue("@path", Path);
                sqlinsertfotoCommand.Parameters.AddWithValue("@desc", Descricao);
                sqlinsertfotoCommand.Parameters.AddWithValue("@dataFoto", Data);
                try
                {
                    conn.Open();
                    sqlinsertfotoCommand.ExecuteNonQuery();
                    LabelOk.Text = "Inserida fotografia!";
                }
                catch (Exception exc)
                {

                    LabelErr.Text = exc.Source + "-" + exc.Message;
                }
                finally
                {
                    conn.Close();
                }
            }

        }

        protected void ButtonCancelar_Click(object sender, EventArgs e)
        {

        }
    }
}